import { regGetDetailList, regGetShopCartData } from "@/api";
import { getuuid } from "@/utils/uuid_token";
export default {
    namespaced: true,
    actions: {
        async getdetaildata({ commit }, id) {
            const result = await regGetDetailList(id)
            // console.log("$$$$", result)
            if (result.code == 200) {
                commit("GETDETAILDATA", result.data)
            }
        },
        //!!这里不需要将数据存起来 ，购物车数据信息的更新 是后端在操作数据 返回给vue 再重新渲染
        async addUpdataShopCart({ commit }, { skuId, skuNum }) {
            const result = await regGetShopCartData(skuId, skuNum)
            // console.log(result)
            if (result.code == 200) {
                return "ok"
            } else {
                return Promise.reject(new Error("fail"))
            }
        }
    },
    mutations: {
        GETDETAILDATA(state, value) {
            state.detailState = value
        }
    },
    state: {
        detailState: {},
        //得到游客id  且每一个游客id 是独立的
        uuid_token: getuuid()
    },
    getters: {
        //geters一般的用法是：简化数据的写法
        price(state) {
            return state.detailState.price
        },
        categoryView(state) {
            //后面兼容{} 是因为在数据没有从服务器过来时，标签里面没有数据会报错，就写{}来代替，避免报错
            return state.detailState.categoryView || {}
        },
        skuInfo(state) {
            return state.detailState.skuInfo || {}
        },
        spuSaleAttrList(state) {
            return state.detailState.spuSaleAttrList || []
        },

    },

}